# pokegra handled in data/graphics/pokegra.mk

# NARC_FILES handles prereqs for move_narc
# MSGDATA_COMPILETIME_DEPENDENCIES handles prereqs for msgdata

MSGDATA_DIR := $(BUILD)/text
MSGDATA_NARC := $(BUILD_NARC)/msg_data.narc
MSGDATA_TARGET := $(FILESYS)/a/0/2/7
MSGDATA_DEPENDENCIES_DIR := data/text
MSGDATA_DEPENDENCIES := $(wildcard $(MSGDATA_DEPENDENCIES_DIR)/*)
MSGDATA_COMPILETIME_DEPENDENCIES_DIR := $(BUILD)/rawtext
#MSGDATA_COMPILETIME_DEPENDENCIES := $(wildcard $(MSGDATA_COMPILETIME_DEPENDENCIES_DIR)/*.txt)
CHARMAP := charmap.txt


$(BUILD)/rawtext/%.txt: $(BUILD_NARC)/a011.narc $(BUILD_NARC)/a055.narc $(BUILD_NARC)/mondata.narc $(BUILD_NARC)/trainer_text_map.narc scripts/msg_cat.py
	$(PYTHON) scripts/msg_cat.py $(BUILD)/rawtext

# actual msgdata rule at bottom to allow MSGDATA_COMPILETIME_DEPENDENCIES to be fully defined
NARC_FILES += $(MSGDATA_NARC)
REQUIRED_DIRECTORIES += $(MSGDATA_DIR) $(MSGDATA_COMPILETIME_DEPENDENCIES_DIR)


BATTLEHUD_DIR := $(BUILD)/a007
BATTLEHUD_NARC := $(BUILD_NARC)/a007.narc
BATTLEHUD_TARGET := $(FILESYS)/a/0/0/7
BATTLEHUD_DEPENDENCIES_DIR := rawdata/battle_sprite
BATTLEHUD_DEPENDENCIES := $(wildcard $(BATTLEHUD_DEPENDENCIES_DIR)/*)

$(BATTLEHUD_NARC): $(BATTLEHUD_DEPENDENCIES)
	$(NARCHIVE) extract $(BATTLEHUD_TARGET) -o $(BATTLEHUD_DIR) -nf
	for file in $(BATTLEHUD_DEPENDENCIES_DIR)/*.png; do \
		$(GFX) $$file $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCGR -bitdepth 8; \
		$(GFX) $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCGR $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCGR.lz; \
		$(GFX) $$file $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCLR -bitdepth 8; \
		mv $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCGR.lz $(BATTLEHUD_DIR)/$$(basename $$file .png); \
		export FILENAME_TEMP=$$(basename $$file); \
		mv $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .png).NCLR $(BATTLEHUD_DIR)/7_$$(($$(basename $${FILENAME_TEMP#*_} .png)+1)); \
	done
	for file in $(BATTLEHUD_DEPENDENCIES_DIR)/*.pal; do \
		$(GFX) $$file $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .pal).NCLR; \
		mv $(BATTLEHUD_DEPENDENCIES_DIR)/$$(basename $$file .pal).NCLR $(BATTLEHUD_DIR)/$$(basename $$file .pal); \
	done
	for file in $(BATTLEHUD_DEPENDENCIES_DIR)/*.NSCR; do \
		cp $$file $(BATTLEHUD_DIR)/$$(basename $$file .NSCR); \
	done
	rm $(BATTLEHUD_DEPENDENCIES_DIR)/*.NCGR
	$(NARCHIVE) create $@ $(BATTLEHUD_DIR) -nf

NARC_FILES += $(BATTLEHUD_NARC)


MOVEDATA_DIR := $(BUILD)/a011
MOVEDATA_NARC := $(BUILD_NARC)/a011.narc
MOVEDATA_TARGET := $(FILESYS)/a/0/1/1
MOVEDATA_DEPENDENCIES := armips/data/moves.s
MOVEDATA_NAMES_DIR := $(BUILD)/rawtext/750 $(BUILD)/rawtext/751 $(BUILD)/rawtext/003 $(BUILD)/rawtext/749

$(MOVEDATA_NARC): $(MOVEDATA_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(MOVEDATA_DIR) -nf

NARC_FILES += $(MOVEDATA_NARC)
REQUIRED_DIRECTORIES += $(MOVEDATA_DIR) $(MOVEDATA_NAMES_DIR)
MSGDATA_COMPILETIME_DEPENDENCIES += $(BUILD)/rawtext/750.txt $(BUILD)/rawtext/751.txt $(BUILD)/rawtext/003.txt $(BUILD)/rawtext/749.txt

MOVEPARTICLES_DIR := $(BUILD)/a029
MOVEPARTICLES_NARC := $(BUILD_NARC)/a029.narc
MOVEPARTICLES_TARGET := $(FILESYS)/a/0/2/9
MOVEPARTICLES_DEPENDENCIES_DIR := rawdata/move_spa
MOVEPARTICLES_DEPENDENCIES := $(wildcard $(MOVEPARTICLES_DEPENDENCIES_DIR)/*)

$(MOVEPARTICLES_NARC): $(MOVEPARTICLES_DEPENDENCIES)
	$(NARCHIVE) extract $(MOVEPARTICLES_TARGET) -o $(MOVEPARTICLES_DIR) -nf
	cp -r $(MOVEPARTICLES_DEPENDENCIES_DIR)/. $(MOVEPARTICLES_DIR)
	$(NARCHIVE) create $@ $(MOVEPARTICLES_DIR) -nf

NARC_FILES += $(MOVEPARTICLES_NARC)


OPENDEMO_DIR := $(BUILD)/a262
OPENDEMO_NARC := $(BUILD_NARC)/a262.narc
OPENDEMO_TARGET := $(FILESYS)/a/2/6/2
OPENDEMO_DEPENDENCIES_DIR := rawdata/op_demo
OPENDEMO_DEPENDENCIES := $(wildcard $(OPENDEMO_DEPENDENCIES_DIR)/*)

$(OPENDEMO_NARC): $(OPENDEMO_DEPENDENCIES)
	$(NARCHIVE) extract $(OPENDEMO_TARGET) -o $(OPENDEMO_DIR) -nf
	cp -r $(OPENDEMO_DEPENDENCIES_DIR)/. $(OPENDEMO_DIR)
	$(NARCHIVE) create $@ $(OPENDEMO_DIR) -nf

NARC_FILES += $(OPENDEMO_NARC)


MONDATA_DIR := $(BUILD)/a002
MONDATA_NARC := $(BUILD_NARC)/mondata.narc
MONDATA_TARGET := $(FILESYS)/a/0/0/2
MONDATA_DEPENDENCIES := armips/data/mondata.s armips/data/tmlearnset.txt
MONDATA_NAMES_DIR := $(BUILD)/rawtext/237 $(BUILD)/rawtext/238 $(BUILD)/rawtext/817
MONDATA_DESCRIPTIONS_DIR := $(BUILD)/rawtext/803
MONDATA_CLASSIFICATIONS_DIR := $(BUILD)/rawtext/816 $(BUILD)/rawtext/823
MONDATA_HEIGHTS_DIR := $(BUILD)/rawtext/814 $(BUILD)/rawtext/815
MONDATA_WEIGHTS_DIR := $(BUILD)/rawtext/812 $(BUILD)/rawtext/813

$(MONDATA_NARC): $(MONDATA_DEPENDENCIES)
	$(ARMIPS) armips/data/mondata.s
	$(PYTHON) scripts/tm_learnset.py armips/data/tmlearnset.txt
	$(NARCHIVE) create $@ $(MONDATA_DIR) -nf

NARC_FILES += $(MONDATA_NARC)
REQUIRED_DIRECTORIES += $(MONDATA_DIR) $(MONDATA_NAMES_DIR) $(MONDATA_DESCRIPTIONS_DIR) $(MONDATA_CLASSIFICATIONS_DIR) $(MONDATA_HEIGHTS_DIR) $(MONDATA_WEIGHTS_DIR)
MSGDATA_COMPILETIME_DEPENDENCIES += $(BUILD)/rawtext/237.txt $(BUILD)/rawtext/238.txt $(BUILD)/rawtext/803.txt $(BUILD)/rawtext/812.txt $(BUILD)/rawtext/813.txt $(BUILD)/rawtext/814.txt $(BUILD)/rawtext/815.txt $(BUILD)/rawtext/817.txt $(BUILD)/rawtext/823.txt


SPRITEOFFSETS_DIR := $(BUILD)/a180
SPRITEOFFSETS_NARC := $(BUILD_NARC)/spriteoffsets.narc
SPRITEOFFSETS_TARGET := $(FILESYS)/a/1/8/0
SPRITEOFFSETS_DEPENDENCIES := armips/data/spriteoffsets.s

$(SPRITEOFFSETS_NARC): $(SPRITEOFFSETS_DEPENDENCIES)
	$(NARCHIVE) extract $(SPRITEOFFSETS_TARGET) -o $(SPRITEOFFSETS_DIR) -nf
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(SPRITEOFFSETS_DIR) -nf

NARC_FILES += $(SPRITEOFFSETS_NARC)


HEIGHT_DIR := $(BUILD)/a005
HEIGHT_NARC := $(BUILD_NARC)/heighttable.narc
HEIGHT_TARGET := $(FILESYS)/a/0/0/5
HEIGHT_DEPENDENCIES := armips/data/heighttable.s

$(HEIGHT_NARC): $(HEIGHT_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(HEIGHT_DIR) -nf

NARC_FILES += $(HEIGHT_NARC)
REQUIRED_DIRECTORIES += $(HEIGHT_DIR)


DEXAREA_DIR := $(BUILD)/a133
DEXAREA_NARC := $(BUILD_NARC)/dexareas.narc
DEXAREA_TARGET := $(FILESYS)/a/1/3/3
DEXAREA_RAWDATA_DIR := rawdata/files_from_a133
DEXAREA_DEPENDENCIES := armips/data/pokedex/areadata.s

$(DEXAREA_NARC): $(DEXAREA_DEPENDENCIES)
	$(ARMIPS) $^
	cp -r $(DEXAREA_RAWDATA_DIR)/. $(DEXAREA_DIR)
	$(NARCHIVE) create $@ $(DEXAREA_DIR) -nf

NARC_FILES += $(DEXAREA_NARC)
REQUIRED_DIRECTORIES += $(DEXAREA_DIR)


DEXSORT_DIR := a214
DEXSORT_NARC := $(BUILD_NARC)/a214.narc
DEXSORT_TARGET := $(FILESYS)/a/2/1/4
DEXSORT_DEPENDENCIES := armips/data/pokedex/pokedexdata.s

$(DEXSORT_NARC): $(DEXSORT_DEPENDENCIES)
	mkdir -p $(DEXSORT_DIR)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(DEXSORT_DIR) -nf
	rm -r $(DEXSORT_DIR)

NARC_FILES += $(DEXSORT_NARC)


EGGMOVES_DIR := $(BUILD)/kowaza
EGGMOVES_NARC := $(BUILD_NARC)/kowaza.narc
EGGMOVES_TARGET := $(FILESYS)/a/2/2/9
EGGMOVES_TARGET_2 := $(FILESYS)/data/kowaza.narc
EGGMOVES_DEPENDENCIES := armips/data/eggmoves.s

$(EGGMOVES_NARC): $(EGGMOVES_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(EGGMOVES_DIR) -nf

NARC_FILES += $(EGGMOVES_NARC)
REQUIRED_DIRECTORIES += $(EGGMOVES_DIR)


EVOS_DIR := $(BUILD)/a034
EVOS_NARC := $(BUILD_NARC)/a034.narc
EVOS_TARGET := $(FILESYS)/a/0/3/4
EVOS_DEPENDENCIES := armips/data/evodata.s

$(EVOS_NARC): $(EVOS_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(EVOS_DIR) -nf

NARC_FILES += $(EVOS_NARC)
REQUIRED_DIRECTORIES += $(EVOS_DIR)


LEARNSET_DIR := $(BUILD)/a033
LEARNSET_NARC := $(BUILD_NARC)/a033.narc
LEARNSET_TARGET := $(FILESYS)/a/0/3/3
LEARNSET_DEPENDENCIES := armips/data/levelupdata.s

$(LEARNSET_NARC): $(LEARNSET_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(LEARNSET_DIR) -nf

NARC_FILES += $(LEARNSET_NARC)
REQUIRED_DIRECTORIES += $(LEARNSET_DIR)


REGIONALDEX_DIR := $(BUILD)/a138
REGIONALDEX_NARC := $(BUILD_NARC)/a138.narc
REGIONALDEX_TARGET := $(FILESYS)/a/1/3/8
REGIONALDEX_DEPENDENCIES := armips/data/regionaldex.s

$(REGIONALDEX_NARC): $(REGIONALDEX_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(REGIONALDEX_DIR) -nf

NARC_FILES += $(REGIONALDEX_NARC)
REQUIRED_DIRECTORIES += $(REGIONALDEX_DIR)


TRAINERDATA_DIR := $(BUILD)/a055
TRAINERDATA_DIR_2 := $(BUILD)/a056
TRAINERDATA_NARC := $(BUILD_NARC)/a055.narc
TRAINERDATA_NARC_2 := $(BUILD_NARC)/a056.narc
TRAINERDATA_TARGET := $(FILESYS)/a/0/5/5
TRAINERDATA_TARGET_2 := $(FILESYS)/a/0/5/6
TRAINERDATA_DEPENDENCIES := armips/data/trainers/trainers.s
TRAINERDATA_TRAINER_NAMES_DIR := $(BUILD)/rawtext/729

$(TRAINERDATA_NARC): $(TRAINERDATA_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(TRAINERDATA_DIR) -nf
	$(NARCHIVE) create $(TRAINERDATA_NARC_2) $(TRAINERDATA_DIR_2) -nf

NARC_FILES += $(TRAINERDATA_NARC)
REQUIRED_DIRECTORIES += $(TRAINERDATA_DIR) $(TRAINERDATA_DIR_2) $(TRAINERDATA_TRAINER_NAMES_DIR)
MSGDATA_COMPILETIME_DEPENDENCIES += $(BUILD)/rawtext/729.txt


TRAINERTEXT_DIR := $(BUILD)/trainer_text_map
TRAINERTEXT_DIR_2 := $(BUILD)/trainer_text_offsets
TRAINERTEXT_NARC := $(BUILD_NARC)/trainer_text_map.narc
TRAINERTEXT_NARC_2 := $(BUILD_NARC)/trainer_text_offsets.narc
TRAINERTEXT_TARGET := $(FILESYS)/a/0/5/7
TRAINERTEXT_TARGET_2 := $(FILESYS)/a/1/3/1
TRAINERTEXT_DEPENDENCIES := armips/data/trainers/trainertext.s

$(TRAINERTEXT_NARC): $(TRAINERTEXT_DEPENDENCIES)
	touch $(TRAINERTEXT_DIR)/7_0
	$(ARMIPS) $^
	$(PYTHON) scripts/trainer_text.py
	$(NARCHIVE) create $(TRAINERTEXT_NARC) $(TRAINERTEXT_DIR)
	$(NARCHIVE) create $(TRAINERTEXT_NARC_2) $(TRAINERTEXT_DIR_2)

NARC_FILES += $(TRAINERTEXT_NARC)
REQUIRED_DIRECTORIES += $(TRAINERTEXT_DIR) $(TRAINERTEXT_DIR_2) $(BUILD)/rawtext/728
MSGDATA_COMPILETIME_DEPENDENCIES += $(BUILD)/rawtext/728.txt

#FOOTPRINTS_DIR := $(BUILD)/a069
FOOTPRINTS_NARC := $(BUILD_NARC)/a069.narc
FOOTPRINTS_TARGET := $(FILESYS)/a/0/6/9
FOOTPRINTS_DEPENDENCIES_DIR := rawdata/footprints
FOOTPRINTS_DEPENDENCIES := $(wildcard $(FOOTPRINTS_DEPENDENCIES_DIR)/*)

$(FOOTPRINTS_NARC): $(FOOTPRINTS_DEPENDENCIES)
	$(NARCHIVE) create $@ $(FOOTPRINTS_DEPENDENCIES_DIR) -nf

NARC_FILES += $(FOOTPRINTS_NARC)


MOVE_ANIM_SCRIPT_OUTPUT_DIR := $(BUILD)/move
REQUIRED_DIRECTORIES += $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)


MOVEANIM_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/move_anim
MOVEANIM_NARC := $(BUILD_NARC)/a010.narc
MOVEANIM_TARGET := $(FILESYS)/a/0/1/0
MOVEANIM_DEPENDENCIES_DIR := armips/move/move_anim

MOVEANIM_SRCS := $(wildcard $(MOVEANIM_DEPENDENCIES_DIR)/*.s)
MOVEANIM_OBJS := $(patsubst $(MOVEANIM_DEPENDENCIES_DIR)/%.s,$(MOVEANIM_DIR)/0_%,$(MOVEANIM_SRCS))

$(MOVEANIM_DIR)/0_%:$(MOVEANIM_DEPENDENCIES_DIR)/%.s
	$(ARMIPS) $<

$(MOVEANIM_NARC): $(MOVEANIM_OBJS)
	$(NARCHIVE) create $@ $(MOVEANIM_DIR) -nf

NARC_FILES += $(MOVEANIM_NARC)
REQUIRED_DIRECTORIES += $(MOVEANIM_DIR)


MOVESUBANIM_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/move_sub_anim
MOVESUBANIM_NARC := $(BUILD_NARC)/a061.narc
MOVESUBANIM_TARGET := $(FILESYS)/a/0/6/1
MOVESUBANIM_DEPENDENCIES_DIR := armips/move/move_sub_anim

MOVESUBANIM_SRCS := $(wildcard $(MOVESUBANIM_DEPENDENCIES_DIR)/*.s)
MOVESUBANIM_OBJS := $(patsubst $(MOVESUBANIM_DEPENDENCIES_DIR)/%.s,$(MOVESUBANIM_DIR)/1_%,$(MOVESUBANIM_SRCS))

$(MOVESUBANIM_DIR)/1_%:$(MOVESUBANIM_DEPENDENCIES_DIR)/%.s
	$(ARMIPS) $<

$(MOVESUBANIM_NARC): $(MOVESUBANIM_OBJS)
	$(NARCHIVE) create $@ $(MOVESUBANIM_DIR) -nf

NARC_FILES += $(MOVESUBANIM_NARC)
REQUIRED_DIRECTORIES += $(MOVESUBANIM_DIR)


MOVE_SEQ_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/battle_move_seq
MOVE_SEQ_OBJ_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/objects/battle_move_seq
MOVE_SEQ_NARC := $(BUILD_NARC)/a000.narc
MOVE_SEQ_TARGET := $(FILESYS)/a/0/0/0
MOVE_SEQ_DEPENDENCIES_DIR := data/battle_scripts/moves

MOVE_SEQ_SRCS := $(wildcard $(MOVE_SEQ_DEPENDENCIES_DIR)/*.s)
MOVE_SEQ_OBJS := $(patsubst $(MOVE_SEQ_DEPENDENCIES_DIR)/%.s,$(MOVE_SEQ_DIR)/0_%,$(MOVE_SEQ_SRCS))

$(MOVE_SEQ_DIR)/0_%:$(MOVE_SEQ_DEPENDENCIES_DIR)/%.s
	$(AS) -c $< -o $(patsubst $(MOVE_SEQ_DEPENDENCIES_DIR)/%.s,$(MOVE_SEQ_OBJ_DIR)/0_%.o,$<)
	$(LD) -T linker.ld -o $(patsubst $(MOVE_SEQ_DEPENDENCIES_DIR)/%.s,$(MOVE_SEQ_OBJ_DIR)/0_%_linked.o,$<) $(patsubst $(MOVE_SEQ_DEPENDENCIES_DIR)/%.s,$(MOVE_SEQ_OBJ_DIR)/0_%.o,$<)
	$(OBJCOPY) -O binary $(patsubst $(MOVE_SEQ_DEPENDENCIES_DIR)/%.s,$(MOVE_SEQ_OBJ_DIR)/0_%_linked.o,$<) $@

$(MOVE_SEQ_NARC): $(MOVE_SEQ_OBJS)
	$(NARCHIVE) create $@ $(MOVE_SEQ_DIR) -nf

$(OUTPUT):$(LINK)

NARC_FILES += $(MOVE_SEQ_NARC)
REQUIRED_DIRECTORIES += $(MOVE_SEQ_DIR) $(MOVE_SEQ_OBJ_DIR)


BATTLE_EFF_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/battle_eff_seq
BATTLE_EFF_OBJ_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/objects/battle_eff_seq
BATTLE_EFF_NARC := $(BUILD_NARC)/a030.narc
BATTLE_EFF_TARGET := $(FILESYS)/a/0/3/0
BATTLE_EFF_DEPENDENCIES_DIR := data/battle_scripts/effects

BATTLE_EFF_SRCS := $(wildcard $(BATTLE_EFF_DEPENDENCIES_DIR)/*.s)
BATTLE_EFF_OBJS := $(patsubst $(BATTLE_EFF_DEPENDENCIES_DIR)/%.s,$(BATTLE_EFF_DIR)/0_%,$(BATTLE_EFF_SRCS))

$(BATTLE_EFF_DIR)/0_%:$(BATTLE_EFF_DEPENDENCIES_DIR)/%.s
	$(AS) -c $< -o $(patsubst $(BATTLE_EFF_DEPENDENCIES_DIR)/%.s,$(BATTLE_EFF_OBJ_DIR)/0_%.o,$<)
	$(LD) -T linker.ld -o $(patsubst $(BATTLE_EFF_DEPENDENCIES_DIR)/%.s,$(BATTLE_EFF_OBJ_DIR)/0_%_linked.o,$<) $(patsubst $(BATTLE_EFF_DEPENDENCIES_DIR)/%.s,$(BATTLE_EFF_OBJ_DIR)/0_%.o,$<)
	$(OBJCOPY) -O binary $(patsubst $(BATTLE_EFF_DEPENDENCIES_DIR)/%.s,$(BATTLE_EFF_OBJ_DIR)/0_%_linked.o,$<) $@

$(BATTLE_EFF_NARC): $(BATTLE_EFF_OBJS)
	$(NARCHIVE) create $@ $(BATTLE_EFF_DIR) -nf

NARC_FILES += $(BATTLE_EFF_NARC)
REQUIRED_DIRECTORIES += $(BATTLE_EFF_DIR) $(BATTLE_EFF_OBJ_DIR)


BATTLE_SUB_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/battle_sub_seq
BATTLE_SUB_OBJ_DIR := $(MOVE_ANIM_SCRIPT_OUTPUT_DIR)/objects/battle_sub_seq
BATTLE_SUB_NARC := $(BUILD_NARC)/a001.narc
BATTLE_SUB_TARGET := $(FILESYS)/a/0/0/1
BATTLE_SUB_DEPENDENCIES_DIR := data/battle_scripts/subscripts

BATTLE_SUB_SRCS := $(wildcard $(BATTLE_SUB_DEPENDENCIES_DIR)/*.s)
BATTLE_SUB_OBJS := $(patsubst $(BATTLE_SUB_DEPENDENCIES_DIR)/%.s,$(BATTLE_SUB_DIR)/1_%,$(BATTLE_SUB_SRCS))

$(BATTLE_SUB_DIR)/1_%:$(BATTLE_SUB_DEPENDENCIES_DIR)/%.s
	$(AS) -c $< -o $(patsubst $(BATTLE_SUB_DEPENDENCIES_DIR)/%.s,$(BATTLE_SUB_OBJ_DIR)/1_%.o,$<)
	$(LD) -T linker.ld -o $(patsubst $(BATTLE_SUB_DEPENDENCIES_DIR)/%.s,$(BATTLE_SUB_OBJ_DIR)/1_%_linked.o,$<) $(patsubst $(BATTLE_SUB_DEPENDENCIES_DIR)/%.s,$(BATTLE_SUB_OBJ_DIR)/1_%.o,$<)
	$(OBJCOPY) -O binary $(patsubst $(BATTLE_SUB_DEPENDENCIES_DIR)/%.s,$(BATTLE_SUB_OBJ_DIR)/1_%_linked.o,$<) $@

$(BATTLE_SUB_NARC): $(BATTLE_SUB_OBJS)
	$(NARCHIVE) create $@ $(BATTLE_SUB_DIR) -nf

NARC_FILES += $(BATTLE_SUB_NARC)
REQUIRED_DIRECTORIES += $(BATTLE_SUB_DIR) $(BATTLE_SUB_OBJ_DIR)


ITEMGFX_DIR := $(BUILD)/a018
ITEMGFX_NARC := $(BUILD_NARC)/a018.narc
ITEMGFX_TARGET := $(FILESYS)/a/0/1/8
ITEMGFX_DEPENDENCIES_DIR := data/graphics/item

ITEMGFX_SRCS := $(wildcard $(ITEMGFX_DEPENDENCIES_DIR)/*.png)
ITEMGFX_OBJS := $(patsubst $(ITEMGFX_DEPENDENCIES_DIR)/%.png,$(ITEMGFX_DIR)/9_%-00.NCGR,$(ITEMGFX_SRCS))
ITEMGFX_PALS := $(patsubst $(ITEMGFX_DEPENDENCIES_DIR)/%.png,$(ITEMGFX_DIR)/9_%-01.NCLR,$(ITEMGFX_SRCS))

$(ITEMGFX_DIR)/9_%-00.NCGR:$(ITEMGFX_DEPENDENCIES_DIR)/%.png
	$(GFX) $< $@ -clobbersize -version101 -bitdepth 4

$(ITEMGFX_DIR)/9_%-01.NCLR:$(ITEMGFX_DEPENDENCIES_DIR)/%.png
	$(GFX) $< $@ -ir -bitdepth 4

# go overkill on the removal + support 4-digit removal, so that's fine
$(ITEMGFX_NARC): $(ITEMGFX_OBJS) $(ITEMGFX_PALS)
	$(NARCHIVE) extract $(ITEMGFX_TARGET) -o $(ITEMGFX_DIR) -nf
	for n in $$(seq 797 $$(expr $$(ls $(ITEMGFX_DIR) | wc -l) - 1)); do rm -f $(ITEMGFX_DIR)/8_$$n; done
	for n in $$(seq 797 $$(expr $$(ls $(ITEMGFX_DIR) | wc -l) - 1)); do rm -f $(ITEMGFX_DIR)/8_$$(printf "%04d" $$n); done
	$(NARCHIVE) create $@ $(ITEMGFX_DIR) -nf

NARC_FILES += $(ITEMGFX_NARC)
REQUIRED_DIRECTORIES += $(ITEMGFX_DIR)


OVERWORLDS_DIR := $(BUILD)/pokemonow
OVERWORLDS_NARC := $(BUILD_NARC)/pokemonow.narc
OVERWORLDS_TARGET := $(FILESYS)/a/0/8/1
OVERWORLDS_DEPENDENCIES_DIR := data/graphics/overworlds

OVERWORLDS_SRCS := $(wildcard $(OVERWORLDS_DEPENDENCIES_DIR)/*.png) $(wildcard $(OVERWORLDS_DEPENDENCIES_DIR)/*.bin) $(wildcard $(OVERWORLDS_DEPENDENCIES_DIR)/*.json) $(wildcard $(OVERWORLDS_DEPENDENCIES_DIR)/*.pal)
#OVERWORLDS_SRCS := $(filter-out $(wildcard $(OVERWORLDS_DEPENDENCIES_DIR)/*_shiny.png),$(OVERWORLDS_SRCS))
OVERWORLDS_OBJS := $(patsubst $(OVERWORLDS_DEPENDENCIES_DIR)/%.png,$(OVERWORLDS_DIR)/1_%.btx0,$(OVERWORLDS_SRCS)) $(patsubst $(OVERWORLDS_DEPENDENCIES_DIR)/%.bin,$(OVERWORLDS_DIR)/1_%.bin,$(OVERWORLDS_SRCS))
#OVERWORLDS_OBJ_FILTERS := $(patsubst $(OVERWORLDS_DEPENDENCIES_DIR)/%.png,$(OVERWORLDS_DIR)/3_%,$(OVERWORLDS_SRCS))

# add your own overworld sources here
ALL_OVERWORLDS_SRCS := $(OVERWORLDS_SRCS)
ALL_OVERWORLDS_OBJS := $(OVERWORLDS_OBJS)

#$(OVERWORLDS_DIR)/2_%_shiny:$(OVERWORLDS_DEPENDENCIES_DIR)/%_shiny.png
#	@:

$(OVERWORLDS_DIR)/1_%.btx0:$(OVERWORLDS_DEPENDENCIES_DIR)/%.png $(OVERWORLDS_DEPENDENCIES_DIR)/%.json $(OVERWORLDS_DEPENDENCIES_DIR)/%*.pal
	$(BTX) $< $@

$(OVERWORLDS_DIR)/1_%.bin:$(OVERWORLDS_DEPENDENCIES_DIR)/%.bin
	cp -f $< $@

#$(OVERWORLDS_NARC): $(ALL_OVERWORLDS_SRCS) | overworld_extract $(ALL_OVERWORLDS_OBJS)
$(OVERWORLDS_NARC): $(ALL_OVERWORLDS_SRCS) $(ALL_OVERWORLDS_OBJS)
	$(NARCHIVE) create $@ $(OVERWORLDS_DIR) -nf

NARC_FILES += $(OVERWORLDS_NARC)
REQUIRED_DIRECTORIES += $(OVERWORLDS_DIR)


DEXGFX_DIR := $(BUILD)/dexgfx
DEXGFX_NARC := $(BUILD_NARC)/dexgfx.narc
DEXGFX_TARGET := $(FILESYS)/a/0/6/8
DEXGFX_DEPENDENCIES_DIR := rawdata/dex_gfx
DEXGFX_DEPENDENCIES := $(wildcard $(DEXGFX_DEPENDENCIES_DIR)/*)

$(DEXGFX_NARC): $(DEXGFX_DEPENDENCIES)
	$(NARCHIVE) extract $(DEXGFX_TARGET) -o $(DEXGFX_DIR) -nf
	cp -r $(DEXGFX_DEPENDENCIES_DIR)/. $(DEXGFX_DIR)
	$(NARCHIVE) create $@ $(DEXGFX_DIR) -nf

NARC_FILES += $(DEXGFX_NARC)


BATTLEGFX_DIR := $(BUILD)/battlegfx
BATTLEGFX_NARC := $(BUILD_NARC)/battlegfx.narc
BATTLEGFX_TARGET := $(FILESYS)/a/0/0/8
BATTLEGFX_DEPENDENCIES_DIR := rawdata/battle_gfx
BATTLEWEATHERGFX_DEPENDENCIES_DIR := rawdata/weather_icons
BATTLEGFX_DEPENDENCIES := $(wildcard $(BATTLEGFX_DEPENDENCIES_DIR)/*) $(wildcard $(BATTLEWEATHERGFX_DEPENDENCIES_DIR)/*)

$(BATTLEGFX_NARC): $(BATTLEGFX_DEPENDENCIES)
	$(NARCHIVE) extract $(BATTLEGFX_TARGET) -o $(BATTLEGFX_DIR) -nf
	for n in $$(seq 346 $$(expr $$(ls $(BATTLEGFX_DIR) | wc -l) - 1)); do rm -f $(BATTLEGFX_DIR)/8_$$n; done
	cp -r $(BATTLEGFX_DEPENDENCIES_DIR)/. $(BATTLEGFX_DIR)
	for file in $(BATTLEWEATHERGFX_DEPENDENCIES_DIR)/*.png; do $(GFX) $$file $(BATTLEGFX_DIR)/$$(basename $$file .png)-00.NCGR; $(GFX) $$file $(BATTLEGFX_DIR)/$$(basename $$file .png)-01.NCLR -bitdepth 8 -nopad -comp 10; done
	for file in $(BATTLEWEATHERGFX_DEPENDENCIES_DIR)/*_terrain.png; do $(GFX) $(BATTLEGFX_DIR)/$$(basename $$file .png)-00.NCGR $(BATTLEGFX_DIR)/$$(basename $$file .png)-00.NCGR.lz; rm $(BATTLEGFX_DIR)/$$(basename $$file .png)-00.NCGR; done
	$(NARCHIVE) create $@ $(BATTLEGFX_DIR) -nf

NARC_FILES += $(BATTLEGFX_NARC)


OTHERPOKE_DIR := $(BUILD)/otherpoke
OTHERPOKE_NARC := $(BUILD_NARC)/otherpoke.narc
OTHERPOKE_TARGET := $(FILESYS)/a/1/1/4
OTHERPOKE_DEPENDENCIES_DIR := rawdata/otherpoke
OTHERPOKE_DEPENDENCIES := $(wildcard $(OTHERPOKE_DEPENDENCIES_DIR)/*)

$(OTHERPOKE_NARC): $(OTHERPOKE_DEPENDENCIES)
	$(NARCHIVE) extract $(OTHERPOKE_TARGET) -o $(OTHERPOKE_DIR) -nf
	@rm -f $(OTHERPOKE_DIR)/4_212 $(OTHERPOKE_DIR)/4_213
	$(GFX) $(OTHERPOKE_DEPENDENCIES_DIR)/arceus-fairy-normal.pal $(OTHERPOKE_DIR)/4_212.NCLR -bitdepth 8 -nopad -comp 10
	$(GFX) $(OTHERPOKE_DEPENDENCIES_DIR)/arceus-fairy-shiny.pal $(OTHERPOKE_DIR)/4_213.NCLR -bitdepth 8 -nopad -comp 10
	$(NARCHIVE) create $@ $(OTHERPOKE_DIR) -nf

NARC_FILES += $(OTHERPOKE_NARC)


ENCOUNTER_DIR := $(BUILD)/a037
ENCOUNTER_NARC := $(BUILD_NARC)/encounters.narc
ENCOUNTER_TARGET := $(FILESYS)/a/0/3/7
ENCOUNTER_DEPENDENCIES := armips/data/encounters.s

$(ENCOUNTER_NARC): $(ENCOUNTER_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(ENCOUNTER_DIR) -nf

NARC_FILES += $(ENCOUNTER_NARC)
REQUIRED_DIRECTORIES += $(ENCOUNTER_DIR)


OVERWORLD_DATA_DIR := $(BUILD)/a141
OVERWORLD_DATA_NARC := $(BUILD_NARC)/overworld_properties.narc
OVERWORLD_DATA_TARGET := $(FILESYS)/a/1/4/1
OVERWORLD_DATA_DEPENDENCIES := armips/data/monoverworlds.s

$(OVERWORLD_DATA_NARC):$(OVERWORLD_DATA_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(OVERWORLD_DATA_DIR) -nf

NARC_FILES += $(OVERWORLD_DATA_NARC)
REQUIRED_DIRECTORIES += $(OVERWORLD_DATA_DIR)


SDAT_DIR := $(BUILD)/sdat
SDAT_OBJ_DIR := $(SDAT_DIR)/build
SDAT_FILES_DIR := $(SDAT_DIR)/Files
SDAT_BUILD := $(BUILD_NARC)/gs_sound_data.sdat
SDAT_TARGET := $(FILESYS)/data/sound/gs_sound_data.sdat
SDAT_DEPENDENCIES_DIR := sound/cries

SDAT_SRCS := $(wildcard $(SDAT_DEPENDENCIES_DIR)/*.wav)
SDAT_MED_OBJS := $(patsubst $(SDAT_DEPENDENCIES_DIR)/%.wav,$(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV%/00.swav,$(SDAT_SRCS))
SDAT_SWAR_OBJS := $(patsubst $(SDAT_DEPENDENCIES_DIR)/%.wav,$(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV%.swar,$(SDAT_SRCS))

$(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV%/00.swav:$(SDAT_DEPENDENCIES_DIR)/%.wav
	mkdir -p $(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV$$(basename "$<" .wav)
	$(NTRWAVTOOL) $< $@ 16384 --adpcm-xq $(ADPCMXQ) --temp-file-dir build/sdat/temp

$(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV%.swar:$(SDAT_OBJ_DIR)/WAVARC/WAVE_ARC_PV%/00.swav
	$(SWAV2SWAR) $< $@

# we need to unpack the sdat
# move the swav/swar/sbnk over
# reorder cries 387+ to be numerical order in the FileBlock.json and InfoBlock.json
$(SDAT_BUILD):$(SDAT_SWAR_OBJS)
	$(SDATTOOL) -u $(SDAT_TARGET) $(SDAT_DIR)
	cp -r $(SDAT_OBJ_DIR)/* $(SDAT_FILES_DIR)
	$(PYTHON) scripts/rebuild_json.py
	$(SDATTOOL) -b $@ $(SDAT_DIR)

NARC_FILES += $(SDAT_BUILD)
REQUIRED_DIRECTORIES += $(SDAT_DIR) $(SDAT_OBJ_DIR) $(SDAT_OBJ_DIR)/BANK build/sdat/temp

FONT_DIR := $(BUILD)/font
FONT_NARC := $(BUILD_NARC)/font.narc
FONT_TARGET := $(FILESYS)/a/0/1/6
FONT_DEPENDENCIES_DIR := rawdata/font
FONT_DEPENDENCIES := $(wildcard $(FONT_DEPENDENCIES_DIR)/*)

$(FONT_NARC): $(FONT_DEPENDENCIES)
	$(NARCHIVE) extract $(FONT_TARGET) -o $(FONT_DIR) -nf
	cp -r $(FONT_DEPENDENCIES_DIR)/. $(FONT_DIR)
	$(NARCHIVE) create $@ $(FONT_DIR) -nf

NARC_FILES += $(FONT_NARC)

TEXTBOX_DIR := $(BUILD)/textbox
TEXTBOX_NARC := $(BUILD_NARC)/textbox.narc
TEXTBOX_TARGET := $(FILESYS)/a/0/3/8
TEXTBOX_DEPENDENCIES_DIR := rawdata/textbox
TEXTBOX_DEPENDENCIES := $(wildcard $(TEXTBOX_DEPENDENCIES_DIR)/*)

$(TEXTBOX_NARC): $(TEXTBOX_DEPENDENCIES)
	$(NARCHIVE) extract $(TEXTBOX_TARGET) -o $(TEXTBOX_DIR) -nf
	cp -r $(TEXTBOX_DEPENDENCIES_DIR)/. $(TEXTBOX_DIR)
	$(NARCHIVE) create $@ $(TEXTBOX_DIR) -nf

NARC_FILES += $(TEXTBOX_NARC)


BALL_SPA_DIR := $(BUILD)/ball_spa
BALL_SPA_NARC := $(BUILD_NARC)/ball_spa.narc
BALL_SPA_TARGET := $(FILESYS)/a/0/9/5
BALL_SPA_DEPENDENCIES_DIR := rawdata/ball_spa
BALL_SPA_DEPENDENCIES := $(wildcard $(BALL_SPA_DEPENDENCIES_DIR)/*)

$(BALL_SPA_NARC): $(BALL_SPA_DEPENDENCIES)
	$(NARCHIVE) extract $(BALL_SPA_TARGET) -o $(BALL_SPA_DIR) -nf
	cp -r $(BALL_SPA_DEPENDENCIES_DIR)/. $(BALL_SPA_DIR)
	$(NARCHIVE) create $@ $(BALL_SPA_DIR) -nf

NARC_FILES += $(BALL_SPA_NARC)


PW_POKEGRA_DIR := $(BUILD)/pw_pokegra
PW_POKEGRA_ART_DIR := $(BUILD)/pw_pokegra_int
PW_POKEGRA_NARC := $(BUILD_NARC)/pw_pokegra.narc
PW_POKEGRA_TARGET := $(FILESYS)/a/2/5/6
PW_POKEGRA_DEPENDENCIES_DIR := data/graphics/pokewalker/sprites
PW_POKEGRA_DEPENDENCIES := $(wildcard $(PW_POKEGRA_DEPENDENCIES_DIR)/*)
PW_POKEGRA_OBJS := $(patsubst $(PW_POKEGRA_DEPENDENCIES_DIR)/%.png,$(PW_POKEGRA_DIR)/%.lz,$(PW_POKEGRA_DEPENDENCIES))

$(PW_POKEGRA_ART_DIR)/%.2bpp: $(PW_POKEGRA_DEPENDENCIES_DIR)/%.png
	$(ENCODEPWIMG) 0x600 $< $@

$(PW_POKEGRA_DIR)/%.lz: $(PW_POKEGRA_ART_DIR)/%.2bpp
	$(GFX) $< $@

$(PW_POKEGRA_NARC): $(PW_POKEGRA_OBJS)
	$(NARCHIVE) create $@ $(PW_POKEGRA_DIR) -nf

NARC_FILES += $(PW_POKEGRA_NARC)
REQUIRED_DIRECTORIES += $(PW_POKEGRA_DIR) $(PW_POKEGRA_ART_DIR)


PW_POKEICON_DIR := $(BUILD)/pw_pokeicon
PW_POKEICON_ART_DIR := $(BUILD)/pw_pokeicon_int
PW_POKEICON_NARC := $(BUILD_NARC)/pw_pokeicon.narc
PW_POKEICON_TARGET := $(FILESYS)/a/2/4/8
PW_POKEICON_DEPENDENCIES_DIR := data/graphics/pokewalker/icons
PW_POKEICON_DEPENDENCIES := $(wildcard $(PW_POKEICON_DEPENDENCIES_DIR)/*)
PW_POKEICON_OBJS := $(patsubst $(PW_POKEICON_DEPENDENCIES_DIR)/%.png,$(PW_POKEICON_DIR)/%.lz,$(PW_POKEICON_DEPENDENCIES))

$(PW_POKEICON_ART_DIR)/%.2bpp: $(PW_POKEICON_DEPENDENCIES_DIR)/%.png
	$(ENCODEPWIMG) 0x180 $< $@

$(PW_POKEICON_DIR)/%.lz: $(PW_POKEICON_ART_DIR)/%.2bpp
	$(GFX) $< $@

$(PW_POKEICON_NARC): $(PW_POKEICON_OBJS)
	$(NARCHIVE) create $@ $(PW_POKEICON_DIR) -nf

NARC_FILES += $(PW_POKEICON_NARC)
REQUIRED_DIRECTORIES += $(PW_POKEICON_DIR) $(PW_POKEICON_ART_DIR)


SCR_SEQ_DIR := $(BUILD)/a012
SCR_SEQ_NARC := $(BUILD_NARC)/scr_seq.narc
SCR_SEQ_TARGET := $(FILESYS)/a/0/1/2
SCR_SEQ_DEPENDENCIES_DIR := armips/scr_seq
SCR_SEQ_DEPENDENCIES := $(SCR_SEQ_DEPENDENCIES_DIR)/*

$(SCR_SEQ_NARC): $(SCR_SEQ_DEPENDENCIES)
	$(NARCHIVE) extract $(SCR_SEQ_TARGET) -o $(SCR_SEQ_DIR) -nf
	for file in $^; do $(ARMIPS) $$file; done
	$(NARCHIVE) create $@ $(SCR_SEQ_DIR) -nf

# for convenience, rebuild SCR_SEQ_NARC every build so that DSPRE changes are not overwritten
.PHONY: $(SCR_SEQ_NARC)

NARC_FILES += $(SCR_SEQ_NARC)

HEADBUTT_DIR := $(BUILD)/headbutttrees
HEADBUTT_NARC := $(BUILD_NARC)/headbutt.narc
HEADBUTT_TARGET := $(FILESYS)/a/2/5/2
HEADBUTT_DEPENDENCIES := armips/data/headbutt.s

$(HEADBUTT_NARC): $(HEADBUTT_DEPENDENCIES)
	$(ARMIPS) $^
	$(NARCHIVE) create $@ $(HEADBUTT_DIR) -nf

NARC_FILES += $(HEADBUTT_NARC)
REQUIRED_DIRECTORIES += $(HEADBUTT_DIR)


TRAINER_GFX_DIR := $(BUILD)/trainer_gfx
TRAINER_GFX_NARC := $(BUILD_NARC)/trainer_gfx.narc
TRAINER_GFX_TARGET := $(FILESYS)/a/0/5/8
TRAINER_GFX_DEPENDENCIES_DIR := data/graphics/trainer_gfx
TRAINER_GFX_DEPENDENCIES := $(TRAINER_GFX_DEPENDENCIES_DIR)/*

TRAINER_GFX_PICS := $(wildcard $(TRAINER_GFX_DEPENDENCIES_DIR)/*_enc.png)
TRAINER_GFX_NCGR := $(patsubst $(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png,$(TRAINER_GFX_DIR)/8_%-00.NCGR,$(TRAINER_GFX_PICS))
TRAINER_GFX_PALS := $(patsubst $(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png,$(TRAINER_GFX_DIR)/8_%-01.NCLR,$(TRAINER_GFX_PICS))
TRAINER_GFX_NCER := $(patsubst $(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png,$(TRAINER_GFX_DIR)/8_%-02.NCER,$(TRAINER_GFX_PICS))
TRAINER_GFX_NANR := $(patsubst $(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png,$(TRAINER_GFX_DIR)/8_%-03.NANR,$(TRAINER_GFX_PICS))
TRAINER_GFX_NCBR := $(patsubst $(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png,$(TRAINER_GFX_DIR)/8_%-04.NCGR,$(TRAINER_GFX_PICS))
TRAINER_GFX_OBJS := $(TRAINER_GFX_NCGR) $(TRAINER_GFX_PALS) $(TRAINER_GFX_NCER) $(TRAINER_GFX_NANR) $(TRAINER_GFX_NCBR)

$(TRAINER_GFX_DIR)/8_%-00.NCGR:$(TRAINER_GFX_DEPENDENCIES_DIR)/%.png
	$(GFX) $< $@ -clobbersize -version101 -bitdepth 4 -vram -mappingtype 64

$(TRAINER_GFX_DIR)/8_%-01.NCLR:$(TRAINER_GFX_DEPENDENCIES_DIR)/%.png
	$(GFX) $< $@ -ir -bitdepth 4

$(TRAINER_GFX_DIR)/8_%-02.NCER:$(TRAINER_GFX_DEPENDENCIES_DIR)/%_cell.json
	$(GFX) $< $@

$(TRAINER_GFX_DIR)/8_%-03.NANR:$(TRAINER_GFX_DEPENDENCIES_DIR)/%_anim.json
	$(GFX) $< $@

$(TRAINER_GFX_DIR)/8_%-04.NCGR:$(TRAINER_GFX_DEPENDENCIES_DIR)/%_enc.png
	$(GFX) $< $@ -clobbersize -version101 -bitdepth 4 -scanfronttoback -mwidth 20

$(TRAINER_GFX_NARC): $(TRAINER_GFX_DEPENDENCIES) $(TRAINER_GFX_OBJS)
	$(NARCHIVE) create $@ $(TRAINER_GFX_DIR) -nf

clean_trgfx:
	rm -rf $(TRAINER_GFX_DIR) $(TRAINER_GFX_NARC)

NARC_FILES += $(TRAINER_GFX_NARC)
REQUIRED_DIRECTORIES += $(TRAINER_GFX_DIR)


$(MSGDATA_NARC): $(MSGDATA_DEPENDENCIES) $(MSGDATA_COMPILETIME_DEPENDENCIES)
	$(NARCHIVE) extract $(MSGDATA_TARGET) -o $(MSGDATA_DIR) -nf
	for file in $^; do $(MSGENC) -e -c $(CHARMAP) $$file $(MSGDATA_DIR)/7_$$(basename $$file .txt); done
	$(NARCHIVE) create $@ $(MSGDATA_DIR) -nf
